<template>
  <header class="header" :class="{ 'scrolled': isScrolled }">
    <nav class="nav container">
      <div class="logo">
        <span class="logo-text">&lt;/&gt;</span>
        <span class="logo-name">YourName</span>
      </div>
      <ul class="nav-menu" :class="{ 'active': isMenuOpen }">
        <li v-for="item in menuItems" :key="item.id">
          <a :href="`#${item.id}`" @click="closeMenu" class="nav-link">
            <span class="nav-number">{{ item.number }}</span>
            {{ item.label }}
          </a>
        </li>
      </ul>
      <button class="menu-toggle" @click="toggleMenu" :class="{ 'active': isMenuOpen }">
        <span></span>
        <span></span>
        <span></span>
      </button>
    </nav>
  </header>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'

const isScrolled = ref(false)
const isMenuOpen = ref(false)

const menuItems = [
  { id: 'hero', label: '首页', number: '01' },
  { id: 'about', label: '关于我', number: '02' },
  { id: 'skills', label: '技能', number: '03' },
  { id: 'projects', label: '项目', number: '04' },
  { id: 'experience', label: '经历', number: '05' },
  { id: 'education', label: '教育', number: '06' },
  { id: 'contact', label: '联系', number: '07' }
]

const toggleMenu = () => {
  isMenuOpen.value = !isMenuOpen.value
}

const closeMenu = () => {
  isMenuOpen.value = false
}

const handleScroll = () => {
  isScrolled.value = window.scrollY > 50
}

onMounted(() => {
  window.addEventListener('scroll', handleScroll)
})

onUnmounted(() => {
  window.removeEventListener('scroll', handleScroll)
})
</script>

<style scoped>
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  transition: all 0.3s;
  background: transparent;
}

.header.scrolled {
  background: rgba(10, 14, 39, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px rgba(0, 217, 255, 0.1);
}

.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.2rem;
  font-weight: 700;
}

.logo-text {
  color: var(--accent-blue);
}

.logo-name {
  color: var(--text-primary);
}

.nav-menu {
  display: flex;
  gap: 2rem;
  list-style: none;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

.nav-link:hover {
  color: var(--accent-blue);
}

.nav-number {
  color: var(--accent-blue);
  font-size: 0.8rem;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--accent-blue);
  transition: width 0.3s;
}

.nav-link:hover::after {
  width: 100%;
}

.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.menu-toggle span {
  width: 25px;
  height: 2px;
  background: var(--accent-blue);
  transition: all 0.3s;
}

.menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }

  .nav-menu {
    position: fixed;
    top: 70px;
    right: -100%;
    flex-direction: column;
    background: rgba(26, 31, 58, 0.98);
    width: 100%;
    padding: 2rem;
    transition: right 0.3s;
    backdrop-filter: blur(10px);
  }

  .nav-menu.active {
    right: 0;
  }
}
</style>
